<?php
/**
 * @param unknown_type $smarty
 * @param unknown_type $message       信息文本
 * @param unknown_type $type          0: 提示1:警告 2：确认
 * @param unknown_type $links         跳转路径
 * @param unknown_type $autoRedirect  是否自动跳转
 */
function to_message($smarty,$message,$type=0,$links=array(),$autoRedirect=true,$seconds=3){
	if(count($links) == 0){
        $links[0]['text'] = $GLOBALS['_LANG']['go_back'];
        $links[0]['href'] = 'javascript:history.go(-1)';
    }
    $smarty->assign('message',$message);
    $smarty->assign('type',$type);
    $smarty->assign('links',$links);
    $smarty->assign('default_url', $links[0]['href']);
    $smarty->assign('auto_redirect', $autoRedirect);
    $smarty->assign('seconds', $seconds);
    $smarty->display('common/message.htm');
	
}
/**
 * 页面重定向
 */
function to_redirect($url){
	echo "<script language=\"javascript\">";
	echo "location.href=\"$url\"";
	echo "</script>";
}

function to_int($intStr){
	$intStr = isset($intStr)?$intStr:0;
	$int = intval($intStr);
	if(strval($int) == $intStr){
		return $int;
	}else{
		return -1;
	}
}

function checkLogin(){
	session_start();
	$sess_user = $_SESSION['user'];
	if(isset($sess_user) && count($sess_user)>0){
		return $sess_user;
	}else{
		to_redirect('/member/login.php');
		exit;
	}
}

function getSessionUser(){
	session_start();
	$sess_user = $_SESSION['user'];
	return $sess_user;
}


function nl2p($str){
	if($str == ''){
		return '';
	}
	$order   = array("\r\n", "\n", "\r");
	$replace = '</p><p>';
	$str=str_replace($order, $replace, $str);
	return '<p>'.$str.'</p>';
}

function p2nl($str){
	if($str == ''){
		return '';
	}
	$str = str_replace("</p><p>",'&#13;&#10;',$str);
	$str = str_replace(array("<p>","</p>"),'', $str);
	return $str;
}

function array_insert($arr,$value,$pos=0){
	$fore=($pos==0)?array():array_splice($arr,0,$pos);
	$fore[]=$value;
	$ret=array_merge($fore,$arr);
	return $ret;
}

function getStartEndPage($pagecount, $page, $total,&$start=0,&$end=0){
	$start = $page-($pagecount%2==0?intval($pagecount/2)-1 : intval($pagecount/2));
	$end = $page+intval($pagecount/2);
	if($start<1){
		$start = 1;
		if($total>=$pagecount) $end = $pagecount;
		else $end = $total;
	}
	if($end>$total){
		$end = $total;
		if(($end-$pagecount)>0) $start = $end-$pagecount+1;
		else $start = 1;
	}
	
}



